package day7

import org.apache.spark
import org.apache.spark.sql.{DataFrame, SparkSession}

object Test2 {
  def main(args: Array[String]): Unit = {
    // 目标：掌握自定义聚合函数的创建
    val spark = SparkSession.builder().master("local[*]").appName("ceshi").getOrCreate()

    // 导入隐式转换
    import spark.implicits._

    val df: DataFrame = List(("zhangsan", 20, 1), ("lisi", 20, 1), ("xiaohong", 18, 0)).toDF

    df.createOrReplaceTempView("t_user")

    spark.udf.register("customSum",new CustonSum())

    spark.sql("select customSum(age)  from t_user").show()
  }
}
